package pcb.control.responders 
{
	import com.intel.patterns.responder.IResponder;
	import com.intel.service.ServiceEvent;
	import com.intel.utils.Debugger;
	import pcb.models.ModelLocator;
	
	/**
	 * ...
	 * @author Fintan Boyle
	 */
	internal class AbstractResponder implements IResponder 
	{
		// define common reference to ModelLocator implementation
		protected static var models:ModelLocator = ModelLocator.getInstance();
		
		public function AbstractResponder() 
		{
			
		}
		
		/* INTERFACE com.intel.patterns.responder.IResponder */
		
		/**
		 * Note: This method MUST be overridden in subclass
		 * @param	event 
		 */
		public function result(e:ServiceEvent):void
		{
			//Note: needs to be overridden in subclass
			Debugger.traceOut("result handler needs to be overridden in subclass", Debugger.WARNING);
		}
		
		public function fault(e:ServiceEvent):void
		{
			Debugger.traceOut(e.type + " - " + e.message);
			
			cleanup(e);
		}
		
		/**
		 * Should be called at end of overridden result() handler
		 * @param	e
		 */
		public function cleanup(e:ServiceEvent):void 
		{
			//important for garbage collection
			e.target.removeEventListener(ServiceEvent.RESULT, result);
			e.target.removeEventListener(ServiceEvent.FAULT, fault);
		}
		
	}
	
}